//@charset "utf-8"

//提交数据
$("#ensure").on('click',async function () {
	TaNumber.enSure();
	var hidNowStock = $("#hiddenNowStock").val();
	if (hidNowStock == '') {
		alert('股票格式不对');
		return ;
	}
	var stockStr = $("#view_stock_input").val();
	var stockArr = stockStr.split(" ");
	var stockName = stockArr[1].replace(/\s/g, '');
	var stockCode = hidNowStock;
	//初始化接口
	var clientInterface = new ComClientInterface({'stockcode':stockCode, 'stockname':stockName});

	//获取默认预警方式
	var modestr = await clientInterface.getDefaultAlertMode();

	if(modestr == ''){
		/*$(".s-box").show();
		$(".mask").show();
		$(".s-box").css('top','40px');*/
		//预警警报
		var mode = new Array();
	    mode.push($("#keep_monitor").hasClass("c-on") ? 1 : 0);
	    mode.push($("#show_pop").hasClass("c-on") ? 1 : 0);
	    
	    //mode.push(1);
	    if ($("#show_sounds").hasClass("c-on")) {
	        mode.push(1);
	        mode.push(1);
	        mode.push($("#soundid").val());
	    } else {
	        mode.push(0);
	        mode.push(1);
	        mode.push('');
	    }
	    mode.push($("#keep_iphone").hasClass("c-on") ? 1 : 0);
	    //COCO新增，增加集合竞价
		mode.push($("#call_auction").hasClass("c-on") ? 1 : 0);
	    mode = mode.join(',');
		//设置默认预警方式
		//var clientInterface = new ComClientInterface();
			await clientInterface.setDefaultAlertMode(mode);
	}else{
		var mode = modestr.split(",");
	}
	var checkedDom = $("#ensure").parent().parent().find(".c-on");
		if(checkedDom.length > 0){
			var allParamIsvalid = true;
			var shakeI = 0;
			checkedDom.each(function (i, everyDom){
				var emDom = $(everyDom).siblings('em');
				if ($(emDom).attr('view_valid_msg') == $(emDom).html()) {
					//var pcid = $(emDom).siblings('input').attr('pcid');
					//var pcidd = $(emDom).siblings('input').attr('pcidd');
					var paramName = $(emDom).siblings('input').attr('param');
					var paramValue = $(emDom).siblings('input').val();
					var market = $("#view_stock_input").attr("data-market");
					clientInterface.formatSetSubData(paramName, paramValue, mode, market);
				} else if($(emDom).attr('view_empty_msg') == $(emDom).html() || $(emDom).attr('view_less_msg') == $(emDom).html() || $(emDom).attr('view_max_msg') == $(emDom).html()) {
					if(shakeI == 0){
						shake($(emDom),'shake',1);
						shakeI = 1;
					}
					allParamIsvalid = false;
				}
			});
			if (!allParamIsvalid){
			 	return;
			};
		//设置接口
		await clientInterface.postSetSubData();
		}else{
			var Allwu = 0;
			var InputDom = $(".view_i_select").parent().find("input");
			InputDom.each(function (i, everyDom){
				var emDom = $(everyDom).attr('upmove');
				if(emDom == 1){
					$(everyDom).parent().find(".view_i_select").click();
					$(everyDom).parent().find(".view_i_select").addClass("c-on");
					Allwu = 1;
				}
			});
			if(Allwu == 0){
				$("#view_gonggao").addClass("c-on");
				TaNumber.viewGonggao();
				var paramName = $("#view_gonggao").siblings('input').attr('param');
				var paramValue = $("#view_gonggao").siblings('input').val();
				var market = $("#view_stock_input").attr("data-market");
				clientInterface.formatSetSubData(paramName, paramValue, mode, market);
				await clientInterface.postSetSubData();
			}
		}
	//COCO修改，保存到本地，换手率
	await clientInterface.writeFileContent('ths_subscribe_coco\\huanshoulv.ini',$("#view_huanshoulv_input").val()+"");	

});
$("#way_sure").live('click',async function(){
	//预警警报
	if($(".yj_mode").html() == null){
		var hidNowStock = $("#hiddenNowStock").val();
		if (hidNowStock == '') {
			alert('股票格式不对');
			return ;
		}
		var stockStr = $("#view_stock_input").val();
		var stockArr = stockStr.split(" ");
		var stockName = stockArr[1].replace(/\s/g, '');
		var stockCode = hidNowStock;
		//初始化接口
		var clientInterface = new ComClientInterface({'stockcode':stockCode, 'stockname':stockName});
		var modestr = await clientInterface.getDefaultAlertMode();
		if(modestr == ''){
			//预警警报
			var mode = new Array();
		    mode.push($("#keep_monitor").hasClass("c-on") ? 1 : 0);
		    mode.push($("#show_pop").hasClass("c-on") ? 1 : 0);
		    
		    //mode.push(1);
		    if ($("#show_sounds").hasClass("c-on")) {
		        mode.push(1);
		        mode.push(1);
		        mode.push($("#soundid").val());
		    } else {
		        mode.push(0);
		        mode.push(1);
		        mode.push('');
		    }
		    mode.push($("#keep_iphone").hasClass("c-on") ? 1 : 0);
		    //COCO新增，增加集合竞价
		    mode.push($("#call_auction").hasClass("c-on") ? 1 : 0);
		    mode = mode.join(',');
			//设置默认预警方式
			//var clientInterface = new ComClientInterface();
				await clientInterface.setDefaultAlertMode(mode);
			/*var checkedDom = $("#ensure").parent().parent().find(".c-on");
			if(checkedDom.length > 0){
				var allParamIsvalid = true;
				var shakeI = 0;
				checkedDom.each(function (i, everyDom){
					var emDom = $(everyDom).siblings('em');
					if ($(emDom).attr('view_valid_msg') == $(emDom).html()) {
						var paramName = $(emDom).siblings('input').attr('param');
						var paramValue = $(emDom).siblings('input').val();
						clientInterface.formatSetSubData(paramName, paramValue, mode);
					} else if($(emDom).attr('view_empty_msg') == $(emDom).html()) {
						if(shakeI == 0){
							shake($(emDom),'shake',1);
							shakeI = 1;
						}
						allParamIsvalid = false;
					}
				});
				if (!allParamIsvalid){
				 	return;
				};
			//设置接口
			await clientInterface.postSetSubData();
			}else{
				var Allwu = 0;
				var InputDom = $(".view_i_select").parent().find("input");
				InputDom.each(function (i, everyDom){
					var emDom = $(everyDom).attr('upmove');
					if(emDom == 1){
						$(everyDom).parent().find(".view_i_select").click();
						$(everyDom).parent().find(".view_i_select").addClass("c-on");
						Allwu = 1;
					}
				});
				if(Allwu == 0){
					$("#view_gonggao").addClass("c-on");
					TaNumber.viewGonggao();
					var paramName = $("#view_gonggao").siblings('input').attr('param');
					var paramValue = $("#view_gonggao").siblings('input').val();
					clientInterface.formatSetSubData(paramName, paramValue, mode);
					await clientInterface.postSetSubData();
				}
			}*/

		}else{
			var mode = new Array();
		    mode.push($("#keep_monitor").hasClass("c-on") ? 1 : 0);
		    mode.push($("#show_pop").hasClass("c-on") ? 1 : 0);
		    
		    //mode.push(1);
		    if ($("#show_sounds").hasClass("c-on")) {
		        mode.push(1);
		        mode.push(1);
		        mode.push($("#soundid").val());
		    } else {
		        mode.push(0);
		        mode.push(1);
		        mode.push('');
		    }
		    mode.push($("#keep_iphone").hasClass("c-on") ? 1 : 0);
		    //COCO新增，增加集合竞价
		    mode.push($("#call_auction").hasClass("c-on") ? 1 : 0);
		    mode = mode.join(',');
			//设置默认预警方式
			//var clientInterface = new ComClientInterface();
			await clientInterface.setDefaultAlertMode(mode);
		}
	}else{
		var mode = new Array();
	    mode.push($("#keep_monitor").hasClass("c-on") ? 1 : 0);
	    mode.push($("#show_pop").hasClass("c-on") ? 1 : 0);
	    
	    //mode.push(1);
	    if ($("#show_sounds").hasClass("c-on")) {
	        mode.push(1);
	        mode.push(1);
	        mode.push($("#soundid").val());
	    } else {
	        mode.push(0);
	        mode.push(1);
	        mode.push('');
	    }
	    mode.push($("#keep_iphone").hasClass("c-on") ? 1 : 0);
	    //COCO新增，增加集合竞价
	    mode.push($("#call_auction").hasClass("c-on") ? 1 : 0);
	    mode = mode.join(',');
		var arrmode_m = mode.split(",");
		$(".yj_mode").attr('arrmode_m',arrmode_m);
		if(mode != ''){
	        var modehtml = new Array();
	        modehtml.push(arrmode_m[0] == 1 ? "保持监控" : "");
	        modehtml.push(arrmode_m[1] == 1 ? "弹窗" : "");
			if(arrmode_m[2] == 1){
	            if(arrmode_m[4] == 'alert'){
	               modehtml.push("警报");
	            }else if(arrmode_m[4] == 'up'){
	                modehtml.push("向上");
	            }else if(arrmode_m[4] == '清脆'){
	                modehtml.push("清脆");
	            }
	        }
	        modehtml.push(arrmode_m[5] == 1 ? "程序" : "");
	        //COCO修改，我的预警集合竞价
	        modehtml.push(arrmode_m[6] == 1 ? "集合竞价" : "");
	        modehtml = modehtml.delNull().join('+');
			if(modehtml == ""){
	        	$(".yj_mode").html("--");
	        }else{
	        	$(".yj_mode").html(mCutStr(modehtml,18,'..'));
	        }

	    }
	}
});
$(".fisrtclose").on('click',async function(){
	//初始化接口
	var clientInterface = new ComClientInterface();
	var modestr = await clientInterface.getDefaultAlertMode();
	if(modestr == ''){
		//预警警报
		var mode = new Array();
	    mode.push($("#keep_monitor").hasClass("c-on") ? 1 : 0);
	    mode.push($("#show_pop").hasClass("c-on") ? 1 : 0);
	     
	    //mode.push(1);
	    if ($("#show_sounds").hasClass("c-on")) {
	        mode.push(1);
	        mode.push(1);
	        mode.push($("#soundid").val());
	    } else {
	        mode.push(0);
	        mode.push(1);
	        mode.push('');
	    }
	    mode.push($("#keep_iphone").hasClass("c-on") ? 1 : 0);
	    //集合竞价
	    mode.push($("#call_auction").hasClass("c-on") ? 1 : 0);
	    mode = mode.join(',');
		//设置默认预警方式
		//var clientInterface = new ComClientInterface();
			await clientInterface.setDefaultAlertMode(mode);
	}else{
		$(this).parent().parent().hide();
		$(".mask").hide();
	}
});